import { _decorator, Color, Component, director, instantiate, Label, Node, Prefab, Sprite } from 'cc';
import { LayerBase } from './LayerBase';
import { UserInfo } from './UserInfo';
import { AudioMgr } from '../utils/AudioMgr';
import { StartSceneGameMgr } from './StartSceneGameMgr';
import { UILayerMgr } from './UILayerMgr';
const { ccclass, property } = _decorator;

@ccclass('SelectGatePanel')
export class SelectGatePanel extends LayerBase {

    @property(Node)
    content: Node;
    @property(Prefab)
    selectGateCellItemBtnPre: Node;

    init(somedData?: any): void {
        this.content.removeAllChildren();

        for (let i = 0; i < 99; i++) {
            let pre = instantiate(this.selectGateCellItemBtnPre);
            pre.setParent(this.content);
            pre.getChildByName("Label").getComponent(Label).string = (i + 1).toString();
            if (i < UserInfo.level) {
                pre.on(Node.EventType.TOUCH_START, () => {
                    director.preloadScene("main", () => {
                        UILayerMgr.getIns.closeUILayer(this.node.name);
                        AudioMgr.ins.playOneShot("audio/clickBtn", 0.8);
                        StartSceneGameMgr.ins.sceneGateLevel = i + 1;
                        director.loadScene("main");
                    });
                }, this)
                pre.getChildByName("bg").getComponent(Sprite).color = Color.WHITE;

            }
            else {
                pre.getChildByName("bg").getComponent(Sprite).color = new Color().fromHEX("#919191");
            }


        }
    }

}


